package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;
import Models.Employee;

public class EmployeePresenter extends AbstractPresenter<Employee> {
	final String SINGLEITEM = "employee";
	final String MULTIITEM = "employees";
	
	public ArrayList<Employee> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public Employee tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public Employee tryJSONParseNoHeader(String input){
		try{
			JSONObject jsonHop = new JSONObject(input);
			Employee employee = createItemFromJSONObject(jsonHop);
			return employee;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public Employee createItemFromJSONObject(JSONObject jsonObject){
		Employee employee = new Employee();
		try{
			employee.setAcetaldehyde(jsonObject.getInt("acetaldehyde"));
			employee.setBARApproval(jsonObject.getBoolean("BARApproval"));
			employee.setBBrewingAccess(jsonObject.getBoolean("BBrewingAccess"));
			employee.setBBrewingNot(jsonObject.getBoolean("BBrewingNot"));
			employee.setBCellaringAccess(jsonObject.getBoolean("BCellaringAccess"));
			employee.setBCellaringNot(jsonObject.getBoolean("BCellaringNot"));
			employee.setBLabAccess(jsonObject.getBoolean("BLabAccess"));
			employee.setBPackagingAccess(jsonObject.getBoolean("BPackagingAccess"));
			employee.setBPackagingNot(jsonObject.getBoolean("BPackagingNot"));
			employee.setBPurchasingNot(jsonObject.getBoolean("BPurchasingNot"));
			employee.setBSalesAccess(jsonObject.getBoolean("BSalesAccess"));
			employee.setBSalesNot(jsonObject.getBoolean("BSalesNot"));
			employee.setBTaproomAccess(jsonObject.getBoolean("BTaproomAccess"));
			employee.setDiacetyl(jsonObject.getInt("diacetyl"));
			employee.setDms(jsonObject.getInt("dms"));
			employee.setEmail(jsonObject.getString("empEmail"));
			employee.setEmailPass(jsonObject.getString("empEmailPass"));
			employee.setEmpAxed(jsonObject.getBoolean("empAxed"));
			employee.setFavorites(jsonObject.getString("empFavorites"));
			employee.setFirstName(jsonObject.getString("empFirstName"));
			employee.setId(jsonObject.getInt("empID"));
			employee.setInfected(jsonObject.getInt("infected"));
			employee.setIsoamyl(jsonObject.getInt("isoamyl"));
			employee.setLastName(jsonObject.getString("empLastName"));
			employee.setPhone(jsonObject.getString("empPhone"));
			employee.setPoApproval(jsonObject.getBoolean("empPOApproval"));
			employee.setSysAdmin(jsonObject.getBoolean("empSysAdmin"));
			employee.setTrans2(jsonObject.getInt("trans2"));
			employee.setUserLevel(jsonObject.getInt("userLevel"));
			employee.setUserName(jsonObject.getString("userName"));
			employee.setUserPass(jsonObject.getString("userPass"));
			employee.setBRecipeModAccess(jsonObject.getBoolean("empbRecipeMod"));
			return employee;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(Employee item){
		try{
			JSONObject json = new JSONObject();
			json.put("acetaldehyde", item.getAcetaldehyde());
			json.put("BARApproval", item.isBARApproval());
			json.put("BBrewingAccess", item.isBBrewingAccess());
			json.put("BBrewingNot", item.isBBrewingNot());
			json.put("BCellaringAccess", item.isBCellaringAccess());
			json.put("BCellaringNot", item.isBCellaringNot());
			json.put("BLabAccess", item.isBLabAccess());
			json.put("BPackagingAccess", item.isBPackagingAccess());
			json.put("BPackagingNot", item.isBPackagingNot());
			json.put("BPurchasingNot", item.isBPurchasingNot());
			json.put("BSalesAccess", item.isBSalesAccess());
			json.put("BSalesNot", item.isBSalesNot());
			json.put("BTaproomAccess", item.isBTaproomAccess());
			json.put("diacetyl", item.getDiacetyl());
			json.put("dms", item.getDms());
			json.put("empEmail", item.getEmail());
			json.put("empEmailPass", item.getEmailPass());
			json.put("empAxed", item.isEmpAxed());
			json.put("empFavorites", item.getFavorites());
			json.put("empFirstName", item.getFirstName());
			json.put("empID", item.getId());
			json.put("infected", item.getInfected());
			json.put("isoamyl", item.getIsoamyl());
			json.put("empLastName", item.getLastName());
			json.put("empPhone", item.getPhone());
			json.put("empPOApproval", item.isPoApproval());
			json.put("empSysAdmin", item.isSysAdmin());
			json.put("trans2", item.getTrans2());
			json.put("userLevel", item.getUserLevel());
			json.put("userName", item.getUserName());
			json.put("userPass", item.getUserPass());
			json.put("empbRecipeMod", item.isBRecipeModAccess());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public Employee getEmptyEntity(){
		Employee entity = new Employee();
		return entity;
	}
}
